#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "mytypes.h"
#include <QFile>
#include <QTextStream>
#include <QToolButton>
#include <QListWidget>
#include <QToolBox>
#include <QLCDNumber>
#include <QTime>
#include <QProgressBar>
#include <QPushButton>
#include <atomic>
#include "filefilterdialog.h"
#include <vector>
#include "ToolBox/toolbox.h"
#include "ToolBox/toolpage.h"
#include <QPainter>
#include <mutex>
#include <QMenu>
#include <QAction>
#include "ReportDialog/loginscene.h"
namespace Ui {
class MainWindow;
}

class MainWindow final : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    virtual ~MainWindow() override;
    void Init_Ui();
    void LoadConfig();      //加载配置文件生成界面

    void Init_StatusBar(int w);  //初始化状态栏

    void StartItemCheckFlag(int mcode,int tcode);

    void FinishItemCheclFlag(int mcode,int tcode);

    void ClearCheckFlag(int mocde);             //重新检查时需要清楚检查标记

    void InitFileCheckCondition();

    void InitEmailCheckCondition();

    void InitVirCheckCondition();

    void InitDeepCheckCondition();

    bool Checkreportdialog();
protected:
    void timerEvent(QTimerEvent* tevent) override;

public slots:
    void CheckButton_CLick(Yzty::MODECODE mcode);        //对功能点击进行处理
    void StartNormalCheck();
    void StartSecurityCheck();
    void StartFileCheck();
    void StartDeepCheck();
    void StartVirmachineCheck();
    void StartEmailCheck();
    void StartHardCheck();
    void StartReportCheck();
    void AcceptFinish(Yzty::MODECODE mcode,Yzty::MODECODE tmcode,Yzty::ITEMCODE tcode);             //接收完成消息
    void ProgressMove(Yzty::MODECODE mcode);    //进度条
    void EndingCheck(Yzty::MODECODE mcode);     //结束检查

    bool FileCondtionDialog();
    bool EmailCondtionDialog();
    bool VirCondtionDialog();
    bool DeepConditonDialog();

    void Click_ListWidget_SingleCheck(int mcode,int tcode,const QPoint& pos);

    void SingleCheck(int mcode,int tcode);
private:
    Ui::MainWindow *ui;

    QVector<ToolBox*>                                   _toolBoxs;

    QVector<QToolButton*>                               _toolButtons;

    QVector<QVector<QListWidgetItem*>>                  _tool_items;
    QVector<QVector<QString>>                           _tool_items_labels;
    QVector<QVector<int>>                               _tool_items_nums;       //每一个item对应执行的功能

    QVector<QLCDNumber*>                                _lcdtimes;

    QVector<QProgressBar*>                              _processbars;

    QVector<QPushButton*>                               _checktools;

    QVector<QVector<QListWidget*>>                      _modelListWidget;   //

    std::vector<std::atomic<int>>                       _counts;        //任务计数器

    QVector<bool>                                       _isrun;         //运行标志

    QVector<bool>                                       _isfinish;       //模块完成检查标志

    QVector<int>                                        _timeids;       //时间id

//    std::mutex                                          _accept_mutex;  //互斥models;
    QVector<int>                                        _models;         //每个大块的功能个数

//    QVector<int>                                        _radio;         //每个模块的当前最大完成率

    QVector<QTime>                                      _times;         //计时器

    FileFilterDialog* _filterdialog;                //文件选着过滤对话框
    FileFilterDialog* _virmachinedialog;            //虚拟机对话框
    FileFilterDialog* _emaildialog;                 //邮箱对话框
    FileFilterDialog* _deepdialog;

    QModelIndex                                         _current;

    QMenu*                                              _ListWidgetMenu;
    QVector<QAction*>                                   _ListWidgetActions;
    LoginScene reportconfigdialog;
    int reportdialogflag;
};

#endif // MAINWINDOW_H
